Case Transformation Functions
These are the main functions used in the token processing loop for converting between naming conventions while respecting language keywords.
to= "s"
for _, line := range lines {
tokens := cc_lib.Tokenize(line)
for _, tok := range tokens {
switch from {
case 's':
cc_lib.FromSnake(tok, to, selectedLanguage)
case 'c':
cc_lib.FromCamel(tok, to, selectedLanguage)
case 'p':
cc_lib.FromPascal(tok, to, selectedLanguage)
default:
fmt.Println("Specify correct input output directives")
fmt.Println(help_directives)
os.Exit(1)
}
}
}
| Function | Description |
|---|---|
FromSnake | Converts a snake_case token to a target case: camelCase ('c') or PascalCase ('p'). If the token is a keyword in the selected Language, it is printed unchanged. |
FromCamel | Converts a camelCase token to a target case: snake_case ('s') or PascalCase ('p'). Keywords are preserved. |
FromPascal | Converts a PascalCase token to a target case: camelCase ('c') or snake_case ('s'). Keywords are preserved. |
Parameters (for FromSnake, FromCamel, FromPascal)
| Name | Type | Description |
|---|---|---|
token | string | The token to be transformed from its current case. |
output | byte | Directive specifying the target case: 'c' for camelCase, 'p' for PascalCase, 's' for snake_case. |
lang | *Language | Pointer to a Language struct. If the token is a keyword in this language, it is printed unchanged. |